package com.dcloud.streamweb.log.service.impl;

import com.dcloud.streamweb.log.entity.JobRunLog;
import com.dcloud.streamweb.log.entity.dto.JobRunLogDTO;
import com.dcloud.streamweb.log.mapper.JobRunLogMapper;
import com.dcloud.streamweb.log.service.IJobRunLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: job_run_log
 * @Author: jeecg-boot
 * @Date:   2024-07-25
 * @Version: V1.0
 */
@Service
@Slf4j
public class JobRunLogServiceImpl extends ServiceImpl<JobRunLogMapper, JobRunLog> implements IJobRunLogService {

    @Autowired
    JobRunLogMapper jobRunLogMapper;

    @Override
    public void updateJobRunLogById(JobRunLogDTO jobRunLogDTO) {
        jobRunLogMapper.updatePartById(JobRunLogDTO.toEntity(jobRunLogDTO));
    }

    @Override
    public void updateLogById(String localLog, Long jobRunLogId) {
        try {
            JobRunLog jobRunLog = new JobRunLog();
            jobRunLog.setId(jobRunLogId);
            jobRunLog.setLocalLog(localLog);
            jobRunLogMapper.updatePartById(jobRunLog);
        } catch (Exception e) {
            log.error("更新日志 失败 id={} ,localLog={}", jobRunLogId, localLog, e);
        }
    }
}
